﻿using IMModel.Domain.Common;
using System.Linq;
using System.Diagnostics.Contracts;
using System.Collections.Generic;
namespace IMModel.Domain
{
    /// <summary>
    /// Получает объёмы градаций для показателя 1.1.1
    /// </summary>
    class GradationVolumeFunctionOrderIC : DefaultGradationVolumeFunction
    {
        new public static readonly GradationVolumeFunctionOrderIC Instance =
            new GradationVolumeFunctionOrderIC();

        /// <summary>
        /// Получает объёмы по всем градациям показателя
        /// </summary>
        /// <param name="context"></param>
        /// <param name="sender"></param>
        /// <returns></returns>
        public override RespondentIndexCollection GetVolumes(IndexContext сontext,
            CharacteristicTerm contextTerm, Term sender)
        {
            Contract.Assert(сontext != null);
            Contract.Assert(contextTerm != null);
            Contract.Assert(sender != null);

            RespondentIndexCollection result = new RespondentIndexCollection();
            var a = GetFiltredAnswers(сontext, contextTerm, sender);

            foreach (var answer in a)
            {
                if (sender.IDTerm > 8)
                {
                    result.Add(answer.Respondent.GetMeInOtherTerm(sender), answer.Value);
                }
            }

            Normirovanie(a, result);
            return result;
        }
    }
}